import { get, postStream } from '@/api/Http'

export interface SVGTemplate {
  id: number
  name: string
  description: string
  defaultRatio: string
  defaultWidth: number
  defaultHeight: number
}

export interface GenerateSVGParams {
  type?: string
  content: string
  prompt?: string
  ratio?: string
  width?: number
  height?: number
}

export class SVGApi {
  static async getTemplates(): Promise<{ code: number; message: string; data: SVGTemplate[] }> {
    return get('/utility/svg/templates', {})
  }

  static async generateSVG(params: GenerateSVGParams): Promise<ReadableStreamDefaultReader<Uint8Array>> {
    const response = await postStream('/utility/svg/generate', params)
    
    if (!response.body) {
      throw new Error('No response body')
    }
    
    return response.body.getReader()
  }
}